import Router from 'koa-router'

const { verifyRole, identityExist } = require('../middleware/role.middleware')
const { auth } = require('../middleware/auth.middleware')
const { getRoles, getRolesByname, getPermissions, getRoleById, addRole, updateRole, deleteRole } = require('../controller/role.controller') 
const router = new Router({ prefix: '/roles' })

/**
 * 角色管理模块
 * @description roles
 */
router.get('/', getRoles) // 获取所有角色(分页可选)
router.get('/name', getRolesByname) // 根据名字搜索角色
router.get('/permissions', getPermissions) // 获取角色对应的权限列表
router.get('/:identity', getRoleById) // 根据id获取角色
router.post('/', auth, verifyRole, addRole) // 添加角色
router.put('/:identity', auth, identityExist, updateRole) // 更新角色
router.delete('/:identity', auth, identityExist, deleteRole)
module.exports = router